limsProductMain.productChoosePage = {

    getGridParam : function() {
        var _this = this, columns = limsProductMain.getProductChooseListColumns();
        _this.param.single ? columns.unshift({
            radio : true
        }) : columns.unshift({
            checkbox : true
        });
        return {
            type : 'grid',
            id : 'lims-product-main-choose-list-grid',
            url : limsProductMain.productUrl + '/queries/choosable',
            requestData : _this.param,
            columns : columns,
            filterOpen: true,
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                }
            },
            onRowActive : function(index, row) {
                Gikam.getComp('lims-product-experimental-template-test-choose-list-grid').refresh({
                    url: limsProductMain.etTestUrl + '/queries',
                    requestData: {
                        etId_EQ: row.etId
                    }
                });
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.CONFIRM',
                icon : 'select',
                onClick : function() {
                    Gikam.getLastModal().close(Gikam.getComp('lims-product-main-choose-list-grid').getSelections());
                }
            } ]
        }
    },

    getEtTestGrid : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-product-experimental-template-test-choose-list-grid',
            service : 'limsExperimentalTemplateTestServiceImpl',
            dbTable : 'T_LIMS_EXPERIMENTAL_TEMPLATE_TEST',
            order : {'orderNo':'asc'},
            columns : limsProductMain.getEtTestListColumns(),
        }
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-product-main-choose-list-layout',
            renderTo : Gikam.getLastModal().window.$dom,
            west: {
                width: '50%',
                title: 'T_LIMS_EXPERIMENTAL_TEMPLATE.SERVICE_NAME',
                items: [this.getGridParam()]
            },
            center: {
                title: 'T_LIMS_EXPERIMENTAL_TEMPLATE_TEST.SERVICE_NAME',
                items: [this.getEtTestGrid()]
            },
        });
    },

    init : function(param) {
        this.param = param;
        this.create();
    }
};
